package com.smart.campus.controller;

import com.smart.campus.dto.AttendanceTime;
import com.smart.campus.pojo.ResponseResult;
import com.smart.campus.service.AttendanceTimeServieFeign;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "时间段管理")
@Slf4j
@RestController
@RequestMapping(value = "attendanceTime")
public class AttendanceController {
    @Autowired
    private AttendanceTimeServieFeign attendanceTimeServieFeign;

    @RequestMapping(value = "findList")
    public ResponseResult<List<AttendanceTime>> findList(){
        return new ResponseResult<>(200,"成功",attendanceTimeServieFeign.findList());
    }
    @RequestMapping(value = "addAtt")
    public ResponseResult addAtt(@RequestBody AttendanceTime attendanceTime){
        try {
            attendanceTimeServieFeign.addAtt(attendanceTime);
            return new ResponseResult<>(200,"成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<>(444,"失败");
        }
    }
    @RequestMapping(value = "delAtt")
    public ResponseResult delAtt(@RequestParam(value = "id")Integer id){
        try {
            attendanceTimeServieFeign.delAtt(id);
            return new ResponseResult<>(200,"成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<>(444,"失败");
        }
    }
    @RequestMapping(value = "findAllById")
    public ResponseResult<AttendanceTime> findAttById(@RequestParam(value = "id")Integer id){
        return new ResponseResult<>(200,"成功",attendanceTimeServieFeign.findAttById(id));
    }
    @RequestMapping(value = "update")
    public ResponseResult update(@RequestBody AttendanceTime attendanceTime){
        try {
            attendanceTimeServieFeign.update(attendanceTime);
            return new ResponseResult<>(200,"成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<>(444,"失败");
        }
    }
}
